import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screen_util.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:study_online/entity/Subject.dart';
import 'package:study_online/global/colors.dart';

class GirdViewItem extends StatelessWidget {
  GirdViewItem({
    Key key,
   @required this.girdViewList,
  }) : super(key: key);
  final List<Subject> girdViewList;

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width,
          maxHeight: MediaQuery.of(context).size.height),
      designSize: Size(1080, 2340),
    );
    return Container(
      key: key,
      color: Colors.white,
      child: AnimationLimiter(
        child: GridView.count(
          childAspectRatio: 1.0,
          padding: const EdgeInsets.all(8.0),
          crossAxisCount: 3,
          children: List.generate(
            girdViewList.length,
            (int index) {
              return AnimationConfiguration.staggeredGrid(
                columnCount: 3,
                position: index,
                duration: const Duration(milliseconds: 375),
                child: ScaleAnimation(
                  scale: 0.5,
                  child: FadeInAnimation(
                    child: InkWell(
                      onTap: (){
                        Navigator.pushNamed(context, 'courseDetail', arguments: [
                          '软件工程',
                          'https://img2.baidu.com/it/u=2595301487,393367436&fm=26&fmt=auto',
                          0,
                          1,
                        ]);
                      },
                      child: Container(
                        //color: Colors.orange,
                        margin: EdgeInsets.all(10),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Image.asset(
                              girdViewList[index].cover=='_'?'assets/img/qq.png':girdViewList[index].cover,
                              width: ScreenUtil().setHeight(127),
                              //height: ScreenUtil().setHeight(127),
                              fit: BoxFit.fitHeight,
                            ),
                            Text(
                              girdViewList[index].name,
                              style: TextStyle(
                                fontSize: ScreenUtil().setSp(37),
                                color: AppColors.subtext,
                              ),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}
